<template>
  <div>
    <Button type="success" :to="{path:'bom-add',query:{}}">
      添加BOM
    </Button>

    <Card style="width:100%">
      <row type="flex" justify="space-between">
        <i-col>

          <span class="key" style="margin-left: 20px">产品名称</span>
          <Input v-model="productName" placeholder="请输入产品名称" class="width-condition" style="width: 200px;margin-left: 20px"/>

          <Button type="success"  icon="ios-search" style="margin-left: 50px" @click="find">查询</Button>
        </i-col>
      </row>
    </Card>




    <Table stripe :columns="columns" :data="data"></Table>

    <row style="margin-top: 10px">
      <i-col align="right">
        <Page show-sizer :total="total" show-total @on-change="onChange" @on-page-size-change="onPageSizeChange"/>
      </i-col>
    </row>

  </div>
</template>

<script>
  import {BomFindAll,BomDelete,ProductFindAll} from "../../../api/data"

  export default {
    data() {
      return {
        page: 1,//page 第几页
        pageSize: 10,//pageSize:每页几条数据
        total: 0,
        productList:[],
        productName:'',
        productCode:'',
        columns: [
          {
            title: '产品名称',
            key: 'productName'
          },
          {
            title: '物料名称',
            key: 'materielNo'
          },
          {
            title: '数量',
            key: 'quantity'
          },
          {
            title: '重量',
            key: 'weight'
          },
          {
            title: '操作',
            key: 'action',
            width: 150,
            align: 'center',
            render: (h, params) => {
              return h('div', [
              /*  h('Button', {
                  props: {
                    type: 'primary',
                    size: 'small'
                  },
                  style: {
                    marginRight: '5px'
                  },
                  on: {
                    click: () => {
                      this.$router.push({
                        path: '/order-setting/order-update', query: {
                          orderNo: params.row.orderNo,
                        }
                      })
                    }
                  }
                }, '编辑'),*/
                h('Button', {
                  props: {
                    type: 'error',
                    size: 'small'
                  },
                  on: {
                    click: () => {
                      this.$Modal.confirm({
                        title:'确认删除',
                        content:'是否要删除BOM？',
                        onOk:()=>{
                          this.BomDelete(params.row.productName,params.row.materielNo);
                        },
                        onCancel:()=>{}
                      })
                    },
                  }
                }, '删除')

              ]);
            }
          }
        ],
        data: []
      }
    },
    mounted() {
      this.BomFindAll();
      this.ProductFindAll();
    },
    methods: {
      find(){
        this.BomFindAll();
      },
      BomFindAll() {
        var data = {
          productName:this.productName,
          page: this.page,
          pageSize: this.pageSize,
        };
        BomFindAll(data).then(data => {
          if (data.data.code == 0) {
            this.data = data.data.data.list;
            this.total = data.data.data.total;
          }
        })
      },
      ProductFindAll() {
        var data = {
          page: this.page,
          pageSize: 1000,
        };
        ProductFindAll(data).then(data => {
          if (data.data.code == 0) {
            this.productList = data.data.data.list;
          }
        })
      },
      onPageSizeChange(pageSize) {
        this.page = 1;
        this.pageSize = pageSize;
        this.BomFindAll();
      },
      onChange(page) {
        this.page = page;
        this.BomFindAll();
      },
      BomDelete(productName,materielNo){
        let data = {
          productName:productName,
          materielNo:materielNo
        }
        BomDelete(data).then(res => {
          if (res.data.code == 0) {
            this.$Message.success("删除成功");
            this.BomFindAll();
          }else {
            this.$Message.error("删除失败");
          }
        })
      },
    }
  }
</script>

<style lang="less">

</style>

